#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int minimumDeleteSum(string s1, string s2) {
        int m = s1.size(), n = s2.size();
        if (m == 0)
            return n;
        if (n == 0)
            return m;
        long long sum1 = 0, sum2 = 0;
        for (auto& e : s1)
            sum1 += e;
        for (auto& e : s2)
            sum2 += e;
        s1 = " " + s1, s2 = " " + s2;
        vector<vector<long long>> dp(m + 1, vector<long long>(n + 1, 0));
        for (int i = 1; i <= m; i++)
            for (int j = 1; j <= n; j++) {
                if (s1[i] == s2[j])
                    dp[i][j] = dp[i - 1][j - 1] + s1[i];
                else
                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        return sum1 - dp[m][n] + sum2 - dp[m][n];
    }
};